package calender;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author wxc
 * @Date 2021/3/31 17:06
 */
public class demo01 {
    public static void main(String[] args) {
        Date date = new Date();
        Date monthBegin = getMonthBegin(date);

        Date monthBegin01 = getMonthBegin01(date);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(monthBegin);
        String format1 = simpleDateFormat.format(monthBegin01);
        System.out.println(format);
        System.out.println(format1);
    }

    public static Date getMonthBegin(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
//        calendar.set(Calendar.DAY_OF_MONTH, -2);
        calendar.add(Calendar.MONTH, -2);
        return calendar.getTime();

    }
    public static Date getMonthBegin01(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
//        calendar.add(Calendar.MONTH, -2);
        return calendar.getTime();

    }
}
